<a href='http://github.com/angular/angular.js/edit/master/src/ng/anchorScroll.js' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this doc</a>



<a href='http://github.com/angular/angular.js/tree/master/src/ng/anchorScroll.js#L3' class='view-source pull-right btn btn-primary'>
  <i class="glyphicon glyphicon-zoom-in">&nbsp;</i>View Source
</a>


<header class="api-profile-header">
  <h1 class="api-profile-header-heading">$anchorScroll</h1>
  <ol class="api-profile-header-structure naked-list step-list">
    
  

    <li>
      - service in module <a href="api/ng">ng</a>
    </li>
  </ol>
</header>



<div class="api-profile-description">
  <p>When called, it checks current value of <code>$location.hash()</code> and scrolls to the related element,
according to rules specified in
<a href="http://dev.w3.org/html5/spec/Overview.html#the-indicated-part-of-the-document">Html5 spec</a>.</p>
<p>It also watches the <code>$location.hash()</code> and scrolls whenever it changes to match any anchor.
This can be disabled by calling <code>$anchorScrollProvider.disableAutoScrolling()</code>.</p>

</div>




<div>
  
  <h2 id="dependencies">Dependencies</h2>
  <ul>
    <li><a href="api/ng/service/$window"><code>$window</code></a></li><li><a href="api/ng/service/$location"><code>$location</code></a></li><li><a href="api/ng/service/$rootScope"><code>$rootScope</code></a></li>
  </ul>
  

    

  <h2 id="usage">Usage</h2>
    
      <p><code>$anchorScroll();</code></p>


    

    
    
    

  
  
  



  
  <h2 id="example">Example</h2><p>

<div>
  <a ng-click="openPlunkr('examples/example-example2')" class="btn pull-right">
    <i class="glyphicon glyphicon-edit">&nbsp;</i>
    Edit in Plunker</a>
  <div class="runnable-example"
      path="examples/example-example2">

   
    <div class="runnable-example-file" 
      name="index.html"
      language="html"
      type="html">
      <pre><code>&lt;div id=&quot;scrollArea&quot; ng-controller=&quot;ScrollCtrl&quot;&gt;&#10;  &lt;a ng-click=&quot;gotoBottom()&quot;&gt;Go to bottom&lt;/a&gt;&#10;  &lt;a id=&quot;bottom&quot;&gt;&lt;/a&gt; You&#39;re at the bottom!&#10;&lt;/div&gt;</code></pre>
    </div>
  
    <div class="runnable-example-file" 
      name="script.js"
      language="js"
      type="js">
      <pre><code>function ScrollCtrl($scope, $location, $anchorScroll) {&#10;  $scope.gotoBottom = function (){&#10;    // set the location.hash to the id of&#10;    // the element you wish to scroll to.&#10;    $location.hash(&#39;bottom&#39;);&#10;&#10;    // call $anchorScroll()&#10;    $anchorScroll();&#10;  };&#10;}</code></pre>
    </div>
  
    <div class="runnable-example-file" 
      name="style.css"
      language="css"
      type="css">
      <pre><code>#scrollArea {&#10;  height: 350px;&#10;  overflow: auto;&#10;}&#10;&#10;#bottom {&#10;  display: block;&#10;  margin-top: 2000px;&#10;}</code></pre>
    </div>
  

    <iframe class="runnable-example-frame" src="examples/example-example2/index.html" name="example-example2"></iframe>
  </div>
</div>

</p>

</div>


